package com.dubbo;

import java.io.File;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;

public class AAA {
    List<Future<Callable>> futureList = new ArrayList<>(10);
    public static void main(String[] args) {
//        for (int i = 1; i <=200 ; i++) {
//            System.out.println(i+"//////////////////");
//            aaaa();
//            System.out.println(i+"//////////////////");
//        }
        File file =new File("C:\\Users\\Administrator\\Desktop");
        File[] files = file.listFiles();
        System.out.println(files.length);
        File file1 =new File("C:\\Users\\Administrator\\Desktop");

        System.out.println(file1.list().length);

    }

    private static void aaaa() {
        ExecutorService executor = new ThreadPoolExecutor(3, 3, 10, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1000), Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
        final  List<Map<String,String>> dataList1111 = new ArrayList<Map<String,String>>();
        List<Integer> dataList = new ArrayList<Integer>();
        for (int i = 0; i < 6; i++) {
            dataList.add(i+1);
        }
        List<CompletableFuture<Map<String,String>>> futures = new ArrayList();
        for (Integer index : dataList) {
            CompletableFuture<Map<String,String>> completableFuture = CompletableFuture.supplyAsync(() -> {
                Map<String, String> tempMap = new HashMap<>();
                System.out.println(Thread.currentThread().getName() + " " + index);
                tempMap.put("data1", index+"");
                tempMap.put("data2", "");
                dataList1111.add(tempMap);
                return tempMap;
            }, executor);
            futures.add(completableFuture);
        }
//        for (Map<String, String> map : dataList1111) {
//            System.out.println(map);
//        }
//        System.out.println("==============");
        CompletableFuture.allOf(futures.toArray(new  CompletableFuture[futures.size()])).join();
        for (CompletableFuture<Map<String, String>> future : futures) {
            try {
//                dataList1111.add(future.get());
                System.out.println(future.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
                System.out.println("==============");
        for (Map<String, String> map : dataList1111) {
            System.out.println(map);
        }

//        for (int i = 0; i < 6; i++) {
//            final int index = i;
//            Future future = executor.submit(new CallableTask1(index));
//            futureList.add(future);
//        }
//        try {
//            // 获取全部并发任务的运行结果
//            for (Future f : futureList) {
//                // 获取任务的返回值，并输出到控制台
//                System.out.println("result：" + f.get());
//            }
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        }
        // 关闭线程池
        executor.shutdown();
    }

    static class CallableTask1 implements Callable<Integer> {
        Integer i;

        public CallableTask1(Integer i) {
            this.i = i;
        }

        @Override
        public Integer call() throws Exception {
            System.out.println(Thread.currentThread().getName() + " " + i);
            return i;
        }
    }

}

